<?php

/**
 * @Author: king
 * @Date:   2019-05-05 20:09:04
 * @Last Modified by:   king
 * @Last Modified time: 2019-05-18 20:34:52
 */
namespace App\Tools\Validates;

use App\Tools\Validate;

class LanmeiAnswerComment extends Validate
{
    protected $rule = [
        'grade' => 'require|integer|gradeCheck',
        'tag_ids' => 'require|tagLenCheck',
        'content' => 'max:30'
    ];

    protected $message = [
        'grade.require' => '请选择评分',
        'grade.integer' => '标签参数异常',
        'grade.gradeCheck' => '标签参数异常',
        'tag_ids.require' => '请选择标签',
        'tag_ids.tagLenCheck' => '最多可以添加3个标签哦',
        'content.max' => '评价最多30字',
    ];

    /**
     * 标签长度校验
     * @param $value
     * @return bool
     */
    protected function tagLenCheck($value)
    {
        return count($value) > 3 ? false : true;
    }

    /**
     * 评分值校验
     * @param $value
     * @return bool
     */
    protected function gradeCheck($value)
    {
        return in_array($value, [1, 2, 3, 4, 5]) ? true : false;
    }
}
